package cn.edu.scau.cmi.linhongyu.hibernate.util;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.linhongyu.hibernate.dao.StudentDAO;
import cn.edu.scau.cmi.linhongyu.hibernate.dao.TeacherDAO;
import cn.edu.scau.cmi.linhongyu.hibernate.domain.Student;
import cn.edu.scau.cmi.linhongyu.hibernate.util.ApplicationContextUtil;
import cn.edu.scau.cmi.linhongyu.hibernate.util.HibernateSessionFactoryUtil;



public class SpringController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TextArea msg;


    @FXML
    void initialize() {
        assert msg != null : "fx:id=\"msg\" was not injected: check your FXML file 'Spring.fxml'.";
        ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
		StudentDAO studentDAO=(StudentDAO) ac.getBean("studentDAO");
		List Students = studentDAO.findAll();
		Iterator<?> StudentIterator = Students.iterator();
		while(StudentIterator.hasNext()){
			Student Student = (Student) StudentIterator.next();
			System.out.println("调用DAO后的名字是："+Student.getName());
			msg.appendText("调用DAO后的名字是："+Student.getName()+'\n');
		}
    }

}
